package cn.spike.rockcc.mq.consumer;

import cn.spike.rockcc.domain.PayOrder;
import cn.spike.rockcc.errorenum.GlobalExceptionCode;
import cn.spike.rockcc.service.IPayOrderService;
import cn.spike.rockcc.util.AssertUtil;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author:spike
 * @create:2023-03-23 15:39
 */
@RocketMQMessageListener(
        consumerGroup = "service-consumer-payOrder",
        topic = "order-delay-topic",
        selectorExpression = "order-delay-tags",
        messageModel = MessageModel.BROADCASTING
)
@Component
public class PayOrderDelayConsumer implements RocketMQListener<String> {

    @Autowired
    private IPayOrderService payOrderService;

    @Override
    public void onMessage(String orderNo) {
        PayOrder payOrder = payOrderService.selectByOrderNo(orderNo);
        AssertUtil.isNotNull(payOrder, GlobalExceptionCode.ORDER_CONSUME_EXCEPTION);
        if(!payOrder.getPayStatus().equals(PayOrder.PAY_SUCCESS))
            payOrderService.orderTimeOut(payOrder);
    }
}
